//  ========== 
//  = 宾和   忘记密码业务JS = 
//  ========== 
var token;
var Main = function() {
	mui.init({
		swipeBack: false //启用右滑关闭功能
	});
	this.init();
	this.even();
	this.loadData();
};
Main.prototype = {
	init: function() {
		function guid() {
			function s4() {
				return Math.floor((1 + Math.random()) * 0x10000)
					.toString(16)
					.substring(1);
			}
			return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
				s4() + '-' + s4() + s4() + s4();
		}
		token = guid();
	},
	even: function() {
		function refreshimg(){
			$("#imgCode").val("");
			var url = server_url + "/getCode.do";
			$('#btn-sendImg').attr("src", url + "?token=" + token + "&d=" + Math.random());
		}
		/**刷新图片验证码*/
		$('#btn-sendImg').on('tap', function() {
			refreshimg();
		});
		
		function checkPhone(phone) {
			if(!phone) {
				mui.toast("请输入手机号");
				return false;
			}
			if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))) {
				mui.toast("请输入正确的手机号码");
				return false;
			}
			return true;
		}
		/** 忘记密码校验绑定手机号码*/
		$("#btn-checkPhone").on('tap', function() {
			var telphone = $("#telphone").val();
			var checkCode = $("#checkCode").val();
			if(!checkPhone(telphone)){
				return false;
			}
			if(!checkCode){
				mui.toast('请输入验证码');
			}
			var url = server_url + "/user/checkUerBpCustMember.do";
			var param = {
				"isMobiel": isMobile,
				"checkCode": checkCode,
				"regType" : "telphone",
				"token" : token,
				"telphone": telphone
			}
			$.getJSON(url, param, function(retData) {
				if(retData.errMsg) {
					mui.toast(retData.errMsg);
					refreshimg();
				} else {
					window.location.href = "forgetPassword.html?telphone="+telphone;
				}
			});
		});
	},
	loadData: function() {
		var url = server_url + "/getCode.do";
		$('#btn-sendImg').attr("src", url + "?token=" +token);
	}
}